
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title></title>  <link rel="icon" href="/template/pc1/images/wmh_favicon.ico" type="image/x-icon" />
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="/template/pc1/images/wmh_favicon.ico">
    <link href="https://res.szzsi.cn/plugins/hplus/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="https://res.szzsi.cn/plugins/hplus/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="https://res.szzsi.cn/plugins/hplus/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="https://res.szzsi.cn/plugins/hplus/css/animate.css" rel="stylesheet">
    <link href="https://res.szzsi.cn/plugins/hplus/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="https://res.szzsi.cn/plugins/hplus/css/plugins/toastr/toastr.min.css" rel="stylesheet">
    <script src="https://res.szzsi.cn/plugins/hplus/js/plugins/toastr/toastr.min.js"></script>
    <link href="https://res.szzsi.cn/css/common.css" rel="stylesheet" type="text/css" />
    <style>
        .laydate_bottom {
            height: 30px;
        }
    </style>

    <script src="/res/plugins/laydate/laydate.js"></script>
</head>

<body class="white-bg">
<div class="path">
    财务管理 &raquo; 培养津贴
</div>
<div class="wrapper wrapper-content">
    <input type="hidden" name="dataLevel" id="dataLevel" value="1">
    <input type="hidden" name="yesterday" id="yesterday" value="${yesterday}"/>
    <div class="row">
        <div class="col-sm-12" >
            <div class="alert alert-warning alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                当日营业额：<label class="totalAmount"></label> &nbsp;分红比例：<label class="rewardPercent"></label> &nbsp;分红人数：<label class="rewardNum"></label> &nbsp;分红金额：<label class="rewardCash"></label>
            </div>
            <div class="btn-group">
                <button class="reward btn btn-primary" type="button" data="1">一级分红</button>
                <button class="reward btn btn-white" type="button" data="2">二级分红</button>
                <button class="reward btn btn-white" type="button" data="3">三级分红</button>
                <button class="reward btn btn-white" type="button" data="4">四级分红</button>
                <button class="reward btn btn-white" type="button" data="5">五级分红</button>
                <button class="reward btn btn-white" type="button" data="6">六级分红</button>
            </div>

            <div id="toolbar">
                日期：<input class="laydate-icon" id="start" style="width:200px; margin-right:10px;" value="${yesterday}"/>
                <button type="button" class="btn btn-primary" onclick="look()">查询</button>
                <button type="button" class="btn btn-warning" onclick="exportprofit()">导出</button>
                <div class="form-inline" role="form">
                    <button id="ok" type="button" class="btn btn-warning">生成分红金额</button>
                </div>
            </div>
            <table id="cpTableEvents" data-toggle="table" data-mobile-responsive="true">
                <thead>
                <tr>
                    <th data-field="number" data-formatter="numberFormatter">序号</th>
                    <th data-field="code">会员ID</th>
                    <th data-field="username">会员昵称</th>
                    <th data-field="phone">联系方式</th>
                    <th data-field="rewardnum">值荐会员</th>
                    <th data-field="profit">分红金额</th>
                    <th data-field="status" data-formatter="boolFormatter">分红状态</th>
                    <th data-field="profitDate">日期</th>
                    <th data-field="distribution" data-formatter="opFormatter"><a href="javascript:void(0)" onclick="distribution();" style="color: red">[一键分配]</a></th>
                </tr>
                </thead>
            </table>

        </div>
    </div>
</div>
<script src="https://res.szzsi.cn/plugins/hplus/js/jquery.min.js?v=2.1.4"></script>
<script src="https://res.szzsi.cn/plugins/hplus/js/bootstrap.min.js?v=3.3.6"></script>
<script src="https://res.szzsi.cn/plugins/hplus/js/content.js?v=1.0.0"></script>
<script src="https://res.szzsi.cn/plugins/hplus/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="https://res.szzsi.cn/plugins/hplus/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="https://res.szzsi.cn/plugins/hplus/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="https://res.szzsi.cn/plugins/hplus/js/plugins/layer/layer.min.js"></script>
<script src="https://res.szzsi.cn/plugins/hplus/js/plugins/toastr/toastr.min.js"></script>

<script>
    function exportprofit(){
        var profitDate=$("#start").val();
        var dataLevel=$("#dataLevel").val();
        location.href = 'exportprofit?profitDate='+profitDate+'&dataLevel='+dataLevel+'';
    }
    function look(){
        var profitDate=$("#start").val();//生成分红日期
        var dataLevel=$("#dataLevel").val();
        if(!profitDate){
            layer.msg("请选择日期!");
            return;
        }
        $('#cpTableEvents').bootstrapTable("refresh",{query: {type:dataLevel,profitDate:profitDate}});
    }
    function numberFormatter(value, row, index){
        return index+1;
    }
    function opFormatter(value, row, index){
        var html='';
        if(row.status){
            html+='<a href="javascript:void(0)" );>[已分配]</a>';
        }else{
            //html+='<a href="javascript:void(0)" onclick="distribution(\''+row.id+'\');" style="color: red">[点击分配]</a>';
            html+='<a href="javascript:void(0)" style="color: red">[未分配]</a>';
        }
        return html;
    }
    function boolFormatter(v) {
        if(v)
            return '已分红';
        else
            return '未分红';
    }

    //分配金额
    function distribution(){
        layer.msg("正在分配中...");
        $.ajax({
            method:"post",
            url: '${base}/shop/dividend/distribution',
            data:{
                profitDate:$("#start").val(),
                dataLevel:$("#dataLevel").val(),
            },
            dataType: "json",
            success: function(data) {
                if (data.code == 0) {
                    layer.msg("操作成功...");
                    $('#cpTableEvents').bootstrapTable("refresh",{query: {type: $("#dataLevel").val(),profitDate:$("#start").val()}});
                    //location.href='${base}/shop/dividend/list';
                }
            }
        });
    }

    (function() {
        $('.reward').on('click',function (e) {
            $('.reward').removeClass('btn-primary').addClass('btn-white');
            $(this).removeClass('btn-white').addClass('btn-primary');

            $('#cpTableEvents').bootstrapTable("refresh",{query: {type: $(this).attr('data'),profitDate:$("#start").val()}});
            $("#dataLevel").attr("value",$(this).attr('data'))
        });

        $('#cpTableEvents').bootstrapTable({
            url: "/shop/balancedetail/ajaxPyjtList",
            search: true,
            pagination: true,
            showRefresh: true,
            showToggle: true,
            showColumns: true,
            iconSize: 'outline',
            toolbar: '#toolbar',
            icons: {
                refresh: 'glyphicon-repeat',
                toggle: 'glyphicon-list-alt',
                columns: 'glyphicon-list'
            },
            responseHandler:function (res) {
                $('.totalAmount').html(res.totalAmount+"(元)");//近日营业额
                $('.rewardPercent').html(res.rewardPercent+"%");//分红比例
                $('.rewardNum').html(res.rewardNum+"人");//分红人数
                $('.rewardCash').html(res.rewardCash+"(元)");
                return res.data;
            }
        });
        toastr.options = {
            "positionClass" : "toast-top-center"
        };

    })();

    //生成分红金额
    $("#ok").click(function () {
        var createDate=$("#start").val();//生成分红日期
        var dataLevel=$("#dataLevel").val();
        if(!createDate){
            layer.msg("请选择日期!");
            return;
        }
        layer.msg("正在努力地加载中,请稍后.....")
        $.ajax({
            url: "${base}/shop/balancedetail/createPyjt",
            type: 'POST',
            data:{
                "createDate":createDate,
                "dataLevel":dataLevel
            },
            success: function(data){
                if(data.code == 1){
                    layer.msg(data.desc);

                }else if (data.code == 0){
                    layer.msg("操作成功!");
                    $('#cpTableEvents').bootstrapTable("refresh",{query: {type: $("#dataLevel").val(),profitDate:$("#start").val()}});
                }
            }});
    });
</script>
<script>
    var start = {
        elem: '#start',
        format: 'YYYY-MM-DD hh:mm:ss',
        //min: laydate.now(), //设定最小日期为当前日期
        max: '2099-06-16 23:59:59', //最大日期
        //istime: true,
        istoday: false,
    };
    laydate(start);

</script>
</body>

</html>